# Copyright (c) 2021-2023 Alibaba Cloud Computing Ltd.
# SPDX-License-Identifier: MulanPSL-2.0

import os
import tornado
import logging

from agent.common.config import Config
from agent.controller.backup import BackupHandler
from agent.controller.configure import ConfigureHandler
from agent.controller.method import MethodHandler
from agent.controller.rollback import RollbackHandler
from agent.controller.status import StatusHandler, AvaliableDomainHandler
from agent.controller import load_handler_class

logger = logging.getLogger('common')

def main():
    load_handler_class()
    
    app = tornado.web.Application(handlers=[
        (r"/backup", BackupHandler),
        (r"/rollback", RollbackHandler),
        (r"/configure", ConfigureHandler),
        (r"/method", MethodHandler),
        (r"/status", StatusHandler),
        (r"/avaliable", AvaliableDomainHandler),
    ])
    app.listen(Config.TARGET_PORT)
    logger.info("keenTune-target running")
    tornado.ioloop.IOLoop.current().start()


if __name__ == "__main__":
    try:
        main()
    except KeyboardInterrupt:
        os._exit(0)